package com.dg.river.core.util;
/**
 * @author wangyilin
 * @description: 封装常用时间方法的工具类
 *@date 2019/7/22 0005 10:03
 */
public class DataUtils {

    /**
     * 将时间转换为时间戳
     */
    public static long timeToStamp(String time) {
        String[] my =time.split(":");
        int hour =Integer.parseInt(my[0]);
        int min =Integer.parseInt(my[1]);
        int sec =Integer.parseInt(my[2]);
        long totalSec =hour*3600+min*60+sec;
        return totalSec;
    }

    /**
     * @param
     *
     * @return 时:分:秒
     *
     */
    public static String getHours(long time) {
        long second = time / 1000;
        long hour = second / 60 / 60;
        long minute = (second - hour * 60 * 60) / 60;
        long sec = (second - hour * 60 * 60) - minute * 60;

        String rHour = "";
        String rMin = "";
        String rSs = "";
        // 时
        if (hour < 10) {
            rHour = "0" + hour;
        } else {
            rHour = hour + "";
        }
        // 分
        if (minute < 10) {
            rMin = "0" + minute;
        } else {
            rMin = minute + "";
        }
        // 秒
        if (sec < 10) {
            rSs = "0" + sec;
        } else {
            rSs = sec + "";
        }

        // return hour + "小时" + minute + "分钟" + sec + "秒";
        return rHour + ":" + rMin + ":" + rSs;

    }
}
